#include "Comm.hpp"
#include"Pipe.hpp"
int main()
{
    // 1.获取k值
    key_t key = GetShmKeyorDie();
    cout << "key:" << ToHex(key) << endl;
    // sleep(2);

    // 2.获取共享内存
    int shmid = GetShm(key, defaultsize);
    cout << "shmid:" << shmid << endl;
    // sleep(2);
    // 3.将共享内存和进程进行挂接
    char *addr = (char *)ShmAttach(shmid);
    cout << "Attach shm success, addr: " << ToHex((uint64_t)addr) << endl;

    // sleep(5);

    // 开始通信
    memset(addr, 0, defaultsize);

    Sync syn;
    syn.WritePipeOrDie();


    for (char c = 'A'; c <= 'Z'; c++)
    {
        addr[c - 'A'] = c;
        sleep(1);
        syn.Wakeup();
    }

    ShmDetach(addr);
    cout << "Detach shm success, addr: " << ToHex((uint64_t)addr) << endl;

    sleep(5);
    // DeleteShm(shmid);

    return 0;
}